package cn.edu.scau.cmi.zhangxiyang.client;

import cn.edu.scau.cmi.zhangxiyang.Composite.ConComposite;
import cn.edu.scau.cmi.zhangxiyang.Composite.ConLeaf;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class ConsistenceCompositeClient extends Application{
public void start(Stage primaryStage) {
		
		Stage stage = new Stage();
		BorderPane border = new BorderPane();
		GridPane gp = new GridPane();
		border.setCenter(gp);
		TextArea text = new TextArea();
		border.setBottom(text);
		
		gp.setHgap(10);
		gp.setVgap(10);
		gp.setPadding(new Insets(0, 10, 0, 10));
		
		Label label1 = new Label("姓名：");
		gp.add(label1, 1, 0);
		
		Label label2 = new Label("the chainsmoker");
		gp.add(label2, 2, 0);
		
		Label label3 = new Label("学号：");
		gp.add(label3, 3, 0);
		
		Label label4 = new Label("201627010428");
		gp.add(label4, 4, 0);
		
		Label label5 = new Label("请选择公司：");
		gp.add(label5, 1, 1);
		
		ConComposite company1 = new ConComposite("腾讯");
		ConComposite company = new ConComposite("Google");
		//Leaf worker = null;
		ComboBox combobox = new ComboBox();
		combobox.getItems().addAll("Google","腾讯");
		gp.add(combobox, 2, 1);
		
		Label label6 = new Label("请输入姓名：");
		gp.add(label6, 3, 1);
		
		TextField textField = new TextField();
		gp.add(textField, 4, 1);
		
		Button btn = new Button("申请入职");
		gp.add(btn,1,2);
		
		Label label7 = new Label("请选择公司：");
		gp.add(label7, 1, 1);
		
		Label label8 = new Label("请选择公司：");
		gp.add(label8, 1, 3);
		
		ComboBox combobox1 = new ComboBox();
		combobox1.getItems().addAll("Google","腾讯");
		gp.add(combobox1, 2, 3);
		
		Button btn1 = new Button("显示员工");
		gp.add(btn1,3,3);
		
		Button btn2 = new Button("联合公司");
		gp.add(btn2,1,4);
		
		btn.setOnAction(e -> {  
			if(combobox.getValue() != null && textField.getText() != null) {
				ConLeaf worker = new ConLeaf(textField.getText().toString());
				if("腾讯".equals(combobox.getValue())) {
					company1.add(worker);
					text.setText("入职腾讯成功！！！");
				}
				else {
					company.add(worker);
					text.setText("入职Google成功！！！");
				}
			}
        });
		
		btn1.setOnAction(e -> {  
			if(combobox1.getValue() != null) {
				if("腾讯".equals(combobox1.getValue())) {
					String a = "";
					a += company1.union();
					text.setText(a);
				}
				else {
					String a = "";
					a += company.union();
					text.setText(a);
				}
			}
        });
		
		btn2.setOnAction(e -> {  
			ConComposite UnionCompany = new ConComposite("���Ϲ�˾");
			UnionCompany.add(company1);
			UnionCompany.add(company);
			text.setText("联合公司");
			String a = "";
			a += UnionCompany.union();
			text.setText(a);
        });

		stage.setScene(new Scene(border,500,500));
		stage.setTitle("组合模式");
        stage.show();
	}

	public static void main(String args[]) {
		launch(args);
	}

}
